package com.kitty.game.fight.pet;

import com.kitty.common.utils.SpringUtils;
import com.kitty.game.fight.bean.Fight;
import com.kitty.game.fight.bean.FightObject;
import com.kitty.game.fight.bean.PetFightObject;
import com.kitty.game.fight.book.BookSkillProcessor;
import com.kitty.game.fight.service.FightMessageService;
import com.kitty.game.fight.util.FightMessageUtil;
import com.kitty.game.fight.util.FightRateUtil;
import com.kitty.game.utils.StatusConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 游说之舌
 * 有效回合内临时降低敌方的战斗能力，包括：攻击、防御、速度，也可以使被使用的宠物的忠诚降低
 */
public class YouShuoZhiSheProcessor extends PetSkillProcessor {
    Logger logger = LoggerFactory.getLogger(getClass());
    @Override
    public void trigger(Fight fight, FightObject effector, FightObject target, int skillLevel, Object... args) {
        if (!FightRateUtil.isPetSkillHit(effector, target)) {
            return;
        }
        target.setStatus(bindingStatus(), skillLevel);
        target.setStatusScore(bindingStatus(), 1);

        // 如果目标是宠物 忠诚度降为60%以下，等同召回宠物操作
        if (target.isPet()) {
        	PetFightObject pet = (PetFightObject)target;
        	int reduceLoyal = 20;
            if (BookSkillProcessor.defenseTrigger(target, fight, BookSkillProcessor.JIN_ZHONG)) {
                reduceLoyal = 10;
            }
        	pet.reduceLoyal(reduceLoyal);
        	if (pet.getLoyal() <= 60) {
        		target.setCurrLife(0);
                target.setStatusScore(StatusConst.STATUS_YOU_SHOU_ROUND, 0);
                FightMessageService fightMessageService = SpringUtils.getFightMessageService();
                FightMessageUtil.sendFightPackage(fight, fightMessageService.doActionStart(fight.getRound(), target));
                FightMessageUtil.sendFightPackage(fight, fightMessageService.disappear(target.getId()));
                FightMessageUtil.sendFightPackage(fight, fightMessageService.doActionEnd(target.getId()));
        	}
        }
    }

    @Override
    public Object effect(Fight fight, FightObject effector, FightObject target, Object... args) {
        int hurt = (int) args[0];
        if (true){
//            logger.error("游说之舌不能对怪物起效=={}",effector.getName());
            return hurt;
        }
        int status = bindingStatus();
        //游说成功后降低目标 法伤 物伤 速度数值计算公式如下，
        //游说之舌技能等级*0.001 换算百分比 进行降低，
        if (effector.getStatusScore(status) > 0) {
            hurt = (int)(effector.getStatusScore(status) * 0.999);
        }

        return hurt;
    }

    @Override
    public int bindingStatus() {
        return StatusConst.STATUS_LOYALTY;
    }
}
